public class LongestSubarray {

    public int longestSubarray(int[] nums) {
        int count = 0;
        int ans = 0;
        int l = 0;
        for (int i = 0; i < nums.length; i++) {
            if (nums[i] == 0) count++;
            while (count > 1) {
                if (nums[l++] == 0) count--;
            }
            ans = Math.max(ans, i - l);
        }
        return ans;
    }
}
